let BASE_URL = '';

//通过环境来判断
if(process.env.NODE_ENV === 'development'){
	BASE_URL = 'https://apifoxmock.com/m1/4728220-0-default'
}else{
	
	BASE_URL = 'http://localhost:5173'
}

export function  request (config={}){
	let{
		url,
		data={},
		method = "GET",
		header={}
	} = config
	
	url = BASE_URL + url
	const token =  uni.getStorageSync('token')
	
	header['token'] = token
	
	return new Promise((resolve,reject) =>{
		uni.request({
			url:url,
			data:data,
			method:method,
			header:header,
			success:res =>{
				if(res.data.code===1){
					resolve(res.data)
				}else if(res.data.errCode === 0){
					uni.showModal({
						title:"错误提示",
						content:res.data.errMsg,
						showCancel:false
					})
					reject(res.data)
				}else{
					uni.showToast({
						title:res.data.errMsg,
						icon:"none"
					})
					reject(res.data)
				}
			},
			fail:err =>{
				reject(err)
			}
		})
	})
}